var addBinary = function (a, b) {
  if (a.length !== b.length) {
    // 两端数据不相同 补齐
    let maxLength = a.length > b.length ? a.length : b.length
    let shortArr = a.length > b.length ? b : a
    let arr = (0 / Math.pow(10, maxLength - shortArr.length)).toFixed(maxLength - shortArr.length).substr(2)
    a.length > b.length ? b = arr + b : a = arr + a
  }
  let maxLength = a.length > b.length ? a.length : b.length
  let index = maxLength -1
  let result = ''
  let s1 = a[index]
  let s2 = b[index]
  let param = 0
  while (s1 || s2) {
    let sum = s1 * 1 + s2 * 1 + param * 1
    if (sum > 1) {
      sum = sum > 2 ? 1 : 0
      param = 1
    } else {
      param = 0
    }
    result = sum + '' + result
    index--
    s1 = a[index] || 0
    s2 = b[index] || 0
  }
  if (param) {
    result = param + result
  }
  return result
};
let str1 = "100"
let str2 = "110010"
// 100
console.log(addBinary(str1, str2))